import { cloneDeep } from "lodash-es";

const cacheList: CacheItemRecord[] = [
  { cacheName: "zzj:login_tokens:", cacheKey: "", cacheValue: "", remark: "用户信息" },
  { cacheName: "sys_config:", cacheKey: "", cacheValue: "", remark: "配置信息" },
  { cacheName: "sys_dict:", cacheKey: "", cacheValue: "", remark: "数据字典" },
  { cacheName: "captcha_codes:", cacheKey: "", cacheValue: "", remark: "验证码" },
  { cacheName: "repeat_submit:", cacheKey: "", cacheValue: "", remark: "防重提交" },
  { cacheName: "rate_limit:", cacheKey: "", cacheValue: "", remark: "限流处理" },
  { cacheName: "pwd_err_cnt:", cacheKey: "", cacheValue: "", remark: "密码错误次数" }
];

const cacheItemList: CacheItemRecord[] = [
  {
    cacheName: "zzjlogin_tokens",
    cacheKey: "862fff3f-030a-4bbc-b4ad-b505c6e92feb",
    cacheValue: "{\"@type\":\"com.bige.common.core.domain.model.LoginUser\",\"browser\":\"Chrome 12\",\"deptId\":103L,\"expireTime\":1720805123631,\"ipaddr\":\"127.0.0.1\",\"loginLocation\":\"内网IP\",\"loginTime\":1720769123631,\"os\":\"Windows 10\",\"permissions\":Set[\"*:*:*\"],\"token\":\"862fff3f-030a-4bbc-b4ad-b505c6e92feb\",\"user\":{\"admin\":true,\"avatar\":\"\",\"createBy\":\"admin\",\"createTime\":\"2024-07-07 17:41:52\",\"delFlag\":\"0\",\"dept\":{\"ancestors\":\"0,100,101\",\"children\":[],\"deptId\":103L,\"deptName\":\"研发部门\",\"leader\":\"必哥\",\"orderNum\":1,\"params\":{\"@type\":\"java.util.HashMap\"},\"parentId\":101L,\"status\":\"0\"},\"deptId\":103L,\"email\":\"bg@163.com\",\"loginDate\":\"2024-07-07 22:35:08\",\"loginIp\":\"127.0.0.1\",\"nickName\":\"必哥\",\"params\":{\"@type\":\"java.util.HashMap\"},\"password\":\"$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2\",\"phonenumber\":\"15888888888\",\"remark\":\"管理员\",\"roles\":[{\"admin\":true,\"dataScope\":\"1\",\"deptCheckStrictly\":false,\"flag\":false,\"menuCheckStrictly\":false,\"params\":{\"@type\":\"java.util.HashMap\"},\"roleId\":1L,\"roleKey\":\"admin\",\"roleName\":\"超级管理员\",\"roleSort\":1,\"status\":\"0\"}],\"sex\":\"1\",\"status\":\"0\",\"userId\":1L,\"userName\":\"admin\"},\"userId\":1L,\"username\":\"admin\"}",
    remark: ""
  },
  { cacheName: "sys_config", cacheKey: "sys.account.captchaEnabled", cacheValue: "\"true\"", remark: "" },
  { cacheName: "sys_config", cacheKey: "sys.account.registerUser", cacheValue: "\"false\"", remark: "" },
  { cacheName: "sys_config", cacheKey: "sys.index.sideTheme", cacheValue: "\"theme-dark\"", remark: "" },
  { cacheName: "sys_config", cacheKey: "sys.index.skinName", cacheValue: "\"skin-blue\"", remark: "" },
  { cacheName: "sys_config", cacheKey: "sys.login.blackIPList", cacheValue: "\"\"", remark: "" },
  { cacheName: "sys_config", cacheKey: "sys.user.initPassword", cacheValue: "\"123456\"", remark: "" },
  {
    cacheName: "sys_dict",
    cacheKey: "sys_common_status",
    cacheValue: "[{\"@type\":\"com.bige.common.core.domain.entity.SysDictData\",\"createBy\":\"admin\",\"createTime\":\"2024-07-07 17:41:52\",\"cssClass\":\"\",\"default\":false,\"dictCode\":28L,\"dictLabel\":\"成功\",\"dictSort\":1L,\"dictType\":\"sys_common_status\",\"dictValue\":\"0\",\"isDefault\":\"N\",\"listClass\":\"primary\",\"params\":{\"@type\":\"java.util.HashMap\"},\"remark\":\"正常状态\",\"status\":\"0\"},{\"@type\":\"com.bige.common.core.domain.entity.SysDictData\",\"createBy\":\"admin\",\"createTime\":\"2024-07-07 17:41:52\",\"cssClass\":\"\",\"default\":false,\"dictCode\":29L,\"dictLabel\":\"失败\",\"dictSort\":2L,\"dictType\":\"sys_common_status\",\"dictValue\":\"1\",\"isDefault\":\"N\",\"listClass\":\"danger\",\"params\":{\"@type\":\"java.util.HashMap\"},\"remark\":\"停用状态\",\"status\":\"0\"}]",
    remark: ""
  },
  {
    cacheName: "sys_dict",
    cacheKey: "sys_job_group",
    cacheValue: "[{\"@type\":\"com.bige.common.core.domain.entity.SysDictData\",\"createBy\":\"admin\",\"createTime\":\"2024-07-07 17:41:52\",\"cssClass\":\"\",\"default\":true,\"dictCode\":10L,\"dictLabel\":\"默认\",\"dictSort\":1L,\"dictType\":\"sys_job_group\",\"dictValue\":\"DEFAULT\",\"isDefault\":\"Y\",\"listClass\":\"\",\"params\":{\"@type\":\"java.util.HashMap\"},\"remark\":\"默认分组\",\"status\":\"0\"},{\"@type\":\"com.bige.common.core.domain.entity.SysDictData\",\"createBy\":\"admin\",\"createTime\":\"2024-07-07 17:41:52\",\"cssClass\":\"\",\"default\":false,\"dictCode\":11L,\"dictLabel\":\"系统\",\"dictSort\":2L,\"dictType\":\"sys_job_group\",\"dictValue\":\"SYSTEM\",\"isDefault\":\"N\",\"listClass\":\"\",\"params\":{\"@type\":\"java.util.HashMap\"},\"remark\":\"系统分组\",\"status\":\"0\"}]",
    remark: ""
  },
  {
    cacheName: "sys_dict",
    cacheKey: "sys_job_status",
    cacheValue: "[{\"@type\":\"com.bige.common.core.domain.entity.SysDictData\",\"createBy\":\"admin\",\"createTime\":\"2024-07-07 17:41:52\",\"cssClass\":\"\",\"default\":true,\"dictCode\":8L,\"dictLabel\":\"正常\",\"dictSort\":1L,\"dictType\":\"sys_job_status\",\"dictValue\":\"0\",\"isDefault\":\"Y\",\"listClass\":\"primary\",\"params\":{\"@type\":\"java.util.HashMap\"},\"remark\":\"正常状态\",\"status\":\"0\"},{\"@type\":\"com.bige.common.core.domain.entity.SysDictData\",\"createBy\":\"admin\",\"createTime\":\"2024-07-07 17:41:52\",\"cssClass\":\"\",\"default\":false,\"dictCode\":9L,\"dictLabel\":\"暂停\",\"dictSort\":2L,\"dictType\":\"sys_job_status\",\"dictValue\":\"1\",\"isDefault\":\"N\",\"listClass\":\"danger\",\"params\":{\"@type\":\"java.util.HashMap\"},\"remark\":\"停用状态\",\"status\":\"0\"}]",
    remark: ""
  },
  {
    cacheName: "sys_dict",
    cacheKey: "sys_normal_disable",
    cacheValue: "[{\"@type\":\"com.bige.common.core.domain.entity.SysDictData\",\"createBy\":\"admin\",\"createTime\":\"2024-07-07 17:41:52\",\"cssClass\":\"\",\"default\":true,\"dictCode\":6L,\"dictLabel\":\"正常\",\"dictSort\":1L,\"dictType\":\"sys_normal_disable\",\"dictValue\":\"0\",\"isDefault\":\"Y\",\"listClass\":\"primary\",\"params\":{\"@type\":\"java.util.HashMap\"},\"remark\":\"正常状态\",\"status\":\"0\"},{\"@type\":\"com.bige.common.core.domain.entity.SysDictData\",\"createBy\":\"admin\",\"createTime\":\"2024-07-07 17:41:52\",\"cssClass\":\"\",\"default\":false,\"dictCode\":7L,\"dictLabel\":\"停用\",\"dictSort\":2L,\"dictType\":\"sys_normal_disable\",\"dictValue\":\"1\",\"isDefault\":\"N\",\"listClass\":\"danger\",\"params\":{\"@type\":\"java.util.HashMap\"},\"remark\":\"停用状态\",\"status\":\"0\"}]",
    remark: ""
  },
  {
    cacheName: "sys_dict",
    cacheKey: "sys_notice_status",
    cacheValue: "[{\"@type\":\"com.bige.common.core.domain.entity.SysDictData\",\"createBy\":\"admin\",\"createTime\":\"2024-07-07 17:41:52\",\"cssClass\":\"\",\"default\":true,\"dictCode\":16L,\"dictLabel\":\"正常\",\"dictSort\":1L,\"dictType\":\"sys_notice_status\",\"dictValue\":\"0\",\"isDefault\":\"Y\",\"listClass\":\"primary\",\"params\":{\"@type\":\"java.util.HashMap\"},\"remark\":\"正常状态\",\"status\":\"0\"},{\"@type\":\"com.bige.common.core.domain.entity.SysDictData\",\"createBy\":\"admin\",\"createTime\":\"2024-07-07 17:41:52\",\"cssClass\":\"\",\"default\":false,\"dictCode\":17L,\"dictLabel\":\"关闭\",\"dictSort\":2L,\"dictType\":\"sys_notice_status\",\"dictValue\":\"1\",\"isDefault\":\"N\",\"listClass\":\"danger\",\"params\":{\"@type\":\"java.util.HashMap\"},\"remark\":\"关闭状态\",\"status\":\"0\"}]",
    remark: ""
  },
  {
    cacheName: "sys_dict",
    cacheKey: "sys_notice_type",
    cacheValue: "[{\"@type\":\"com.bige.common.core.domain.entity.SysDictData\",\"createBy\":\"admin\",\"createTime\":\"2024-07-07 17:41:52\",\"cssClass\":\"\",\"default\":true,\"dictCode\":14L,\"dictLabel\":\"通知\",\"dictSort\":1L,\"dictType\":\"sys_notice_type\",\"dictValue\":\"1\",\"isDefault\":\"Y\",\"listClass\":\"warning\",\"params\":{\"@type\":\"java.util.HashMap\"},\"remark\":\"通知\",\"status\":\"0\"},{\"@type\":\"com.bige.common.core.domain.entity.SysDictData\",\"createBy\":\"admin\",\"createTime\":\"2024-07-07 17:41:52\",\"cssClass\":\"\",\"default\":false,\"dictCode\":15L,\"dictLabel\":\"公告\",\"dictSort\":2L,\"dictType\":\"sys_notice_type\",\"dictValue\":\"2\",\"isDefault\":\"N\",\"listClass\":\"success\",\"params\":{\"@type\":\"java.util.HashMap\"},\"remark\":\"公告\",\"status\":\"0\"}]",
    remark: ""
  }
];

const mocks: MockRecord[] = [
  {
    method: "get",
    url: "/api/monitor/server",
    response() {
      const resData: responseType = {
        code: 200,
        msg: "查询成功",
        data: {
          cpu: {
            cpuNum: 12,
            total: 1199900,
            sys: 3.78,
            used: 3.9,
            wait: 0,
            free: 92.07
          },
          mem: {
            total: 13.9,
            used: 10.71,
            free: 3.19,
            usage: 77.07
          },
          jvm: {
            total: 91.93,
            max: 247.5,
            free: 34.6,
            version: "1.8.0_65",
            home: "D:\\JDK\\jre",
            name: "Java HotSpot(TM) Client VM",
            startTime: "2024-07-12 15:18:42",
            usage: 62.36,
            used: 57.33,
            inputArgs: "[-XX:TieredStopAtLevel=1, -Xverify:none, -Dspring.output.ansi.enabled=always, -Dcom.sun.management.jmxremote, -Dspring.jmx.enabled=true, -Dspring.liveBeansView.mbeanDomain, -Dspring.application.admin.enabled=true, -javaagent:D:\\JetBrains\\IntelliJ IDEA 2020.1\\lib\\idea_rt.jar=51084:D:\\JetBrains\\IntelliJ IDEA 2020.1\\bin, -Dfile.encoding=UTF-8]",
            runTime: "0天4小时21分钟"
          },
          sys: {
            computerName: "MS-CFKRSXGRBNQX",
            computerIp: "192.168.31.93",
            userDir: "E:\\bigeJava\\bige-moban",
            osName: "Windows 10",
            osArch: "x86"
          },
          sysFiles: [
            {
              dirName: "C:\\",
              sysTypeName: "NTFS",
              typeName: "本地固定磁盘 (C:)",
              total: "300.0 GB",
              free: "252.1 GB",
              used: "47.9 GB",
              usage: 15.95
            },
            {
              dirName: "D:\\",
              sysTypeName: "NTFS",
              typeName: "本地固定磁盘 (D:)",
              total: "653.4 GB",
              free: "473.6 GB",
              used: "179.8 GB",
              usage: 27.52
            },
            {
              dirName: "E:\\",
              sysTypeName: "NTFS",
              typeName: "本地固定磁盘 (E:)",
              total: "660.0 GB",
              free: "445.1 GB",
              used: "214.9 GB",
              usage: 32.56
            },
            {
              dirName: "F:\\",
              sysTypeName: "NTFS",
              typeName: "本地固定磁盘 (F:)",
              total: "602.0 GB",
              free: "348.4 GB",
              used: "253.6 GB",
              usage: 42.12
            },
            {
              dirName: "G:\\",
              sysTypeName: "NTFS",
              typeName: "本地固定磁盘 (G:)",
              total: "601.0 GB",
              free: "271.2 GB",
              used: "329.9 GB",
              usage: 54.88
            }
          ]
        }
      };

      return resData;
    }
  },
  {
    method: "get",
    url: "/api/monitor/cache",
    response() {
      const resData: responseType = {
        code: 200,
        msg: "查询成功",
        data: {
          commandStats: [
            {
              name: "set",
              value: "17"
            },
            {
              name: "del",
              value: "1"
            },
            {
              name: "info",
              value: "3"
            },
            {
              name: "exists",
              value: "1"
            },
            {
              name: "get",
              value: "66"
            },
            {
              name: "dbsize",
              value: "1"
            },
            {
              name: "setex",
              value: "5"
            },
            {
              name: "ping",
              value: "1"
            },
            {
              name: "keys",
              value: "1"
            }
          ],
          info: {
            aof_rewrite_scheduled: "0",
            keyspace_misses: "1",
            mem_allocator: "jemalloc-3.6.0",
            multiplexing_api: "WinSock_IOCP",
            aof_last_write_status: "ok",
            run_id: "4100ae3dd2c68e2803a2cfb30b4e660d7494c374",
            uptime_in_seconds: "27218",
            maxmemory: "0",
            total_system_memory_human: "0B",
            arch_bits: "64",
            master_repl_offset: "0",
            instantaneous_output_kbps: "1.41",
            total_commands_processed: "95",
            repl_backlog_size: "1048576",
            sync_full: "0",
            sync_partial_err: "0",
            used_cpu_user: "0.45",
            aof_enabled: "0",
            redis_mode: "standalone",
            rdb_changes_since_last_save: "0",
            used_memory_lua: "37888",
            redis_build_id: "dd26f1f93c5130ee",
            connected_slaves: "0",
            expired_keys: "3",
            used_memory: "703024",
            used_memory_rss: "665248",
            rdb_last_bgsave_status: "ok",
            process_id: "4784",
            rejected_connections: "0",
            used_memory_rss_human: "649.66K",
            rdb_bgsave_in_progress: "0",
            cluster_enabled: "0",
            tcp_port: "6379",
            os: "Windows  ",
            aof_current_rewrite_time_sec: "-1",
            repl_backlog_histlen: "0",
            used_cpu_sys: "0.20",
            role: "master",
            aof_last_bgrewrite_status: "ok",
            used_memory_peak_human: "686.55K",
            hz: "10",
            used_memory_human: "686.55K",
            maxmemory_policy: "noeviction",
            mem_fragmentation_ratio: "0.95",
            rdb_last_bgsave_time_sec: "0",
            blocked_clients: "0",
            used_cpu_sys_children: "0.00",
            repl_backlog_active: "0",
            used_cpu_user_children: "0.00",
            sync_partial_ok: "0",
            aof_rewrite_in_progress: "0",
            redis_git_sha1: "00000000",
            client_longest_output_list: "0",
            rdb_current_bgsave_time_sec: "-1",
            aof_last_rewrite_time_sec: "-1",
            config_file: "D:Redis\redis.windows-service.conf",
            loading: "0",
            pubsub_channels: "0",
            used_memory_lua_human: "37.00K",
            db0: "keys=17,expires=1,avg_ttl=20453650",
            migrate_cached_sockets: "0",
            redis_git_dirty: "0",
            total_system_memory: "0",
            connected_clients: "1",
            lru_clock: "9508642",
            pubsub_patterns: "0",
            repl_backlog_first_byte_offset: "0",
            total_net_output_bytes: "69508",
            client_biggest_input_buf: "0",
            executable: "D:Redis\"D:Redis\redis-server.exe\"",
            evicted_keys: "0",
            total_connections_received: "1",
            redis_version: "3.2.100",
            total_net_input_bytes: "17501",
            latest_fork_usec: "22180",
            maxmemory_human: "0B",
            used_memory_peak: "703024",
            keyspace_hits: "65",
            uptime_in_days: "0",
            instantaneous_input_kbps: "0.09",
            rdb_last_save_time: "1720769942",
            instantaneous_ops_per_sec: "1"
          },
          dbSize: 17
        }
      };

      return resData;
    }
  },
  {
    method: "get",
    url: "/api/monitor/cache/getNames",
    response() {
      const resData: responseType = {
        code: 200,
        msg: "查询成功",
        data: cacheList
      }

      return resData;
    }
  },
  {
    method: "get",
    url: "/api/monitor/cache/getKeys/:cacheName",
    response(option) {
      const filterItemList = cacheItemList.filter(item => item.cacheName == option.query.cacheName.replaceAll(':', ''));

      const resData: responseType = {
        code: 200,
        msg: "查询成功",
        data: filterItemList.map(item => item.cacheKey)
      };

      return resData;
    }
  },
  {
    method: "get",
    url: "/api/monitor/cache/getValue/:cacheName/:cacheKey",
    response(option) {

      const filterItem = cacheItemList.find(item =>
        item.cacheName == option.query.cacheName.replaceAll(':', '') && item.cacheKey == option.query.cacheKey
      );

      const resData: responseType = {
        code: filterItem ? 200 : 500,
        msg: filterItem ? "查询成功" : "查询失败",
        data: filterItem
      };

      return resData;
    }
  },
]

export default mocks;